//初始化信息
$(function(){
	getSession();//初始化session对象
	
	queryCkHtml(1,8,"#con1 ul","6","7","9");//信用滨州
	queryCkHtml(1,8,"#con2 ul","7","7","10");//信用山东
	queryCkHtml(1,8,"#con3 ul","8","7","18");//信用国内
	queryCkHtml(1,8,"#con4 ul","9","7","22");//信用国际
	queryCkHtml(1,10,"#redId","30","34","67");//信用红榜
	queryCkHtml(1,10,"#blackId","31","34","68");//信用黑榜
	
	queryTpgd(1,3);//图片滚动
	
	searchcontent();

	queryTZY(1,5,"#tzgg","tzgg");//通知公告
	queryTZY(1,11,"#zcfg","zcfg");//政策法规
	queryTZY(1,11,"#xyyjlist","xyyj");//信用研究
	

	queryimglink(1,8,"#subject dl",2);//惩戒系统 图片
	

	Tab("#TabbedPanels3 ul li");//选项卡
	//queryCollection("#demo1 table",7);//数据采集1
	//queryCollection("#demo2 table",7);//数据采集2
	
	
	querySgs(1,8,1);//许可公示
	querySgs(1,8,2);//处罚公示
	
	//复选框单选事件
	$(':checkbox[name=qy]').each(function(){
		$(this).click(function(){
			if($(this).attr('checked')){
				$(':checkbox[name=qy]').removeAttr('checked');
				$(this).attr('checked','checked');
			}
		}); 
	}); 
	
	 $(":radio").click(function(){
		 var value = $(this).val();
		 if(value=='2'){
			 $(".searchbuttonred").css("background-color","#666666");
			 $(".inputsearchcondition").attr("onblur","if(this.value==''){this.value='该查询暂未开通';this.style.color='#000000'}");
			 $(".inputsearchcondition").attr("onfocus","if(this.value=='该查询暂未开通'){this.value='';this.style.color='#000000'}");
			 $(".inputsearchcondition").attr("value","该查询暂未开通");
		 }else{
			 $(".searchbuttonred").css("background-color","#df0000");
			 $(".inputsearchcondition").attr("value","请输入完整企业名称或个体工商户名称");
			 $(".inputsearchcondition").attr("onblur","if(this.value==''){this.value='请输入完整企业名称或个体工商户名称';this.style.color='#000000'}");
			 $(".inputsearchcondition").attr("onfocus","if(this.value=='请输入完整企业名称或个体工商户名称'){this.value='';this.style.color='#000000'}");
			
		 }
	 });

})


 
//信用动态
function moremsg(){
	var classval="on";
	if(clickmore('#tab1on',classval)){
		location.href='page_list.html?parent=7&menu=9';
	}else if(clickmore('#tab2on',classval)){
		location.href='page_list.html?parent=7&menu=10';
	}else if(clickmore('#tab3on',classval)){
		location.href='page_list.html?parent=7&menu=18';
	}else if(clickmore('#tab4on',classval)){
		location.href='page_list.html?parent=7&menu=22';
	}
}
//信用公示
function morexygs(){
	var classval = "TabbedPanelsTabSelected";
	if(clickmore('#xyxkid',classval)){
		location.href='page_publicity.html?type=1&menu=69&parent=34';
	}else if(clickmore('#xycfid',classval)){
		location.href='page_publicity.html?type=1&menu=70&parent=34';
	}else if(clickmore('#xyredid',classval)){
		location.href='page_list.html?parent=34&menu=67';
	}else if(clickmore('#xyblackid',classval)){
		location.href='page_list.html?parent=34&menu=68';
	}
}
//点击更多时，判断是哪个标签
function clickmore(id,value){
	var val=$(id).attr("class");
	var array=val.split(" ");
	for(var i=0;i<array.length;i++){
		 if(array[i]==value){
			 return true;
		 }
	}
	return false;
	
}

//单机民意调查提交的时候触发
function subPaylist(){
	var typeId = $('#research_select input[name="paylist"]:checked ').val();
	if(typeId==null || typeId==""){
		alert("请选择您要投哪一项");
		return;
	}
	$.ajax({
		  type: "post",
		  url: "../tp/addTp",
		  data: {
			  'typeId':typeId
		  },
		  dataType: "json",
		  success: function(data){
				 var row = data.row;
				 if(row==1){
					 alert("投票成功,感谢您的参与!");
				 }
		  }
	  })
	
}

//点击民意调查查看的时候触发，打开弹出窗口
function searchPaylist(){
	var url = "public/column_chart.html";
	if(navigator.userAgent.indexOf("Chrome") >0 ){  
		var winOption = "edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:560px;DialogHeight=320px";  
				return  window.open(url,window, winOption);  
	}else{  
			return window.open(url,"",'edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:760px;DialogHeight=520px');
	} 
}

//公共信用信息查询选择框变更事件
function searchcontent(){
	
	$(":radio[name=ren]").change(function() {
		if(this.value==1){
			$('#selectcomp').show();
			$(':checkbox[name=qy]').each(function(){
				if(this.value=='bz'){
					$(this).removeAttr('disabled');
					$(this).attr('checked','checked');
				}
			}); 
		}else if(this.value==2){
			$('#selectcomp').hide();
		}
	});
	
}
//跳转到双公示页面
function sgs(type,menu,parent){
	location.href="page_publicity.html?type="+type+"&menu="+menu+"&parent="+parent;
}
//跳转到信用红黑榜页面
function redblack(menu,parent){
	location.href="page_list.html?parent="+parent+"&menu="+menu;
}


//公共信用信息查询
function ggxycx(){
	 var type='';
		var val=$("input[name='inputqyxm']").val();
		var url='';
		if(val=="请输入完整企业名称或个体工商户名称"){
			alert("请输入完整企业名称或个体工商户名称");
		}else if(val==null||val==''){
			alert("请输入完整企业名称或个体工商户名称");
		}else{
			$(':radio[name=ren]').each(function(){
				if(this.value=='1'){//法人
					if($(this).attr("checked")){  
						location.href='page_search_01.html?parent=89&qymc='+encodeURI(encodeURI(val));
					}
					
				}else if(this.value=='2'){//自然人
					if($(this).attr("checked")){ 
						/*location.href='page_search_01.html?xm='+encodeURI(encodeURI(val));*/
					}
				}
			}); 
		}
	
}

//验证登录
function ggxygetSession(url){
	
	$.ajax({
		  type: "post",
		  url: "../qtuser/getSession",
		  dataType: "json",
		  success: function(data){
			  if(data.zt==0){
				 location.href=url;
			  }else{
				 alert('请先登录！');
				 MM_showHideLayers('loginbg','','show');
			  }
		  }
	  })
}

//初始化图片滚动信息
function queryTpgd(page,rows){
	$.ajax({
		  type: "post",
		  url: "../ck/queryCkHtmlQian",
		  data: {
			  'state':'1',//前台显示
			  'ckTypeList':'tpxx',//图片信息
			  'page':page,
			  'rows':rows
		  },
		  dataType: "json",
		  success: function(data){
				
				var list = data.rows;
				 var imgStr = '';
				 $.each(list, function(index, entity){
					 var parent;
					 var menu;
					 if(entity.ckType==6){parent = 7; menu = 9;}
					 if(entity.ckType==7){parent = 7; menu = 10;}
					 if(entity.ckType==8){parent = 7; menu = 18;}
					 if(entity.ckType==9){parent = 7; menu = 22;}
					 imgStr+='<a href="page_news.html?parent='+parent+'&menu='+menu+'&data='+entity.id+'" " target="_blank" ><img src="../images/uploadimg/'
						 +entity.img
						 +'" border="0"/><br /><p class="p1">'
						 +entity.title
						 +'</p></a> ';
				 })
				 $("#slides").append(imgStr);
				 
				 img();
		  }
	  })
	 
}

//初始化双公示信息
function querySgs(start,end,ckType){
	$.ajax({
		  type: "post",
		  url: "../many/querySgs",
		  data: {
			  'ckType':ckType,//1许可2处罚
			  'page':start,
			  'count':end
		  },
		  dataType: "json",
		  error:function(){
		  },
		  success: function(data){
				 var list = data.list;
				
				 var xyhzStr = '';
				 $.each(list, function(index, entity){
					 var nowDate = entity.sjc;
					 var now = new Date(nowDate);
					 var time= now.format("yyyy-MM-dd");
					 if(ckType=='1'||ckType==1){
						
						 xyhzStr+='<li><a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank">'
						 +entity.xdr+
						 entity.mc+'<span>'+time+'</span></a></li>';
					 }else if(ckType=='2'||ckType==2){
						 xyhzStr+='<li><a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank">'
						 +entity.xdrmc
						 +entity.mc+'<span>'+time+'</span></a></li>';
					 }
				})
				 if(ckType=='1'||ckType==1){
					 $("#sgsxk").append(xyhzStr);
					
				 }else if(ckType=='2'||ckType==2){
					 $("#sgscf").append(xyhzStr);
				 }
		  }
	  })
}

//初始化HTML
function queryCkHtml(page,rows,idstr,ckType,parent,menu){
	$.ajax({
		  type: "post",
		  url: "../ck/queryCkHtmlQian",
		  data: {
			  'state':'1',//前台显示
			  'ckType':ckType,//类型
			  'page':page,
			  'rows':rows
		  },
		  dataType: "json",
		  success: function(data){
				 var list = data.rows;
				 var str = '';
				 $.each(list, function(index, entity){
					 var nowDate = entity.createTime;
					 var now = new Date(nowDate);
					 var time= now.format("yyyy-MM-dd");
					 if(ckType=='6'||ckType=='7'||ckType=='8'||ckType=='9'){
						 if(index==0){
							 str+='<li><a style="color: #df0024 " href="page_news.html?parent='+parent+'&menu='+menu+'&data='+entity.id+'" target="_blank">'
							 +entity.title
							 +'<span style="color: #df0024 ">'
							 +time
							 +'</span></a></li>';
						 }else{
							 str+='<li><a href="page_news.html?parent='+parent+'&menu='+menu+'&data='+entity.id+'" target="_blank">'
							 +entity.title
							 +'<span>'
							 +time
							 +'</span></a></li>';
						 }
					 }else{
						 str+='<li><a href="page_news.html?parent='+parent+'&menu='+menu+'&data='+entity.id+'" target="_blank">'
						 +entity.title
						 +'<span>'
						 +time
						 +'</span></a></li>';
					 }
					 
				 })
				 $(idstr).append(str);
		  }
	  })
}



function img(){
	/** 幻灯片 */
	$("#slides").slidesjs({
		width: 360,
    	height: 240,
		play:{
		  active: false,
		  effect: "slide",	// "slide" or "fade".
		  interval: 5000,
		  auto: true,
		  pauseOnHover: true,
		  restartDelay: 2500
		}
	});
	
	/** 图片滚动 */
	var jcarousel = $('#carousel_inner');
		jcarousel.jcarousel({ wrap: 'circular' })
		.jcarouselAutoscroll({
			interval: 3000,
			target: '+=1',
			autostart: true
		});
		$('#left_scroll').jcarouselControl({ target: '-=1' });
        $('#right_scroll').jcarouselControl({ target: '+=1' });
	
	$('#carousel_ul li').each(function(){
		$(this).hover(function(){
			$(this).find('.wrap').stop().show();
		})
	});
}

//初始化通知公告、政策法规、信用研究
function queryTZY(page,rows,idstr,ckTypeList){
	$.ajax({
		  type: "post",
		  url: "../ck/queryCkHtmlQian",
		  data: {
			  'state':'1',//前台显示
			  'ckTypeList':ckTypeList, 
			  'page':page,
			  'rows':rows
		  },
		  dataType: "json",
		  success: function(data){
				 var list = data.rows;
				 var xyhzStr = '';
				 $.each(list, function(index, entity){
					 var nowDate = entity.createTime;
					 var now = new Date(nowDate);
					 var time= now.format("yyyy-MM-dd");
					 var parent;
					 var menu;
					 if(entity.ckType==32){parent = 65; menu = 66;}//通知公告
					 if(entity.ckType==10){parent = 11; menu = 12;}//政策法规
					 if(entity.ckType==21){parent = 11; menu = 43;}
					 if(entity.ckType==22){parent = 11; menu = 44;}
					 if(entity.ckType==23){parent = 11; menu = 45;}
					 if(entity.ckType==11){parent = 23; menu = 24;}//信用研究
					 if(entity.ckType==12){parent = 23; menu = 25;}
					 if(entity.ckType==13){parent = 23; menu = 26;}
					 xyhzStr+='<li><a href="page_news.html?parent='+parent+'&menu='+menu+'&data='+entity.id+'" " target="_blank">'+entity.title+'<span>'+time+'</span></a></li>';
				 })
				 $(idstr).append(xyhzStr);
		  }
	})
}



//初始化图片链接
function queryimglink(page,rows,idstr,linktype){
	$.ajax({
		  type: "post",
		  url: "../link/queryLink",
		  data: {
			  'isDel':'1',//前台显示
			  'imgTextType':'2',
			  'linkType':linktype,//所属类型 2惩戒系统 
			  'page':page,
			  'rows':rows
		  },
		  dataType: "json",
		  success: function(data){
				 var list = data.rows;
				 var str = '';
				
				 $.each(list, function(index, entity){
					 var nowDate = entity.createTime;
					 var now = new Date(nowDate);
					 var time= now.format("yyyy-MM-dd");
					 if(linktype=='3'||linktype=='4'){
						 str='<a href="'+entity.linkUrl+'" target="_blank" class="img"><img src=../../images/uploadimg/'+entity.linkImg+' width="194" height="45" /></a>';
					 }else{
						 if(entity.orderId==1){//1为标题栏
							 if(linktype=='1'){
								 str+='<dt><a href="'+entity.linkUrl+'"><img src=../../images/uploadimg/'+entity.linkImg+' width="640" height="81" />222222222222222222</a><BR />'+entity.linkName+'</dt>';
							 }else {
								 str+='<dt><a href="'+entity.linkUrl+'"><img src=../../images/uploadimg/'+entity.linkImg+' width="640" height="81" />11111</a></dt>';
							 }
						 }else if(entity.orderId%2 ==0){//左侧
							 str+='<dd><a href="'+entity.linkUrl+'"><img src=../../images/uploadimg/'+entity.linkImg+' width="316" height="85" /></a></dd>';
						 }else if(entity.orderId%2 !=0){//右侧
							 str+='<dd class="norightsp"><a href="'+entity.linkUrl+'"><img src=../../images/uploadimg/'+entity.linkImg+' width="316" height="85" /></a></dd>';
						 }
					 }
				 })
				
				 $(idstr).append(str);//subject
		  }
	  })
}

//获取选项卡当前文本信息
function Tab(name){
	$("#TabbedPanels3 .TabbedPanelsTabGroup a").click(function(){
		$(name).each(function(){
			var type=$(this).attr("class");
			if(type!=null&&type.length>15){
				var type=$(this).html();
				if(type=="通知公告"){ window.location.href="../home/page_list.html?parent=65&menu=66";}
				if(type=="政策法规"){ window.location.href="../home/page_list.html?parent=11&menu=12";}
				if(type=="信用研究"){ window.location.href="../home/page_list.html?parent=23&menu=24";}
			}
		})
	})
}

//信用动态more
function  dtmore(){
	
	$("#con1").css("display","none");
	$("#con2").css("display","none");
	$("#con3").css("display","none");
	$("#con4").css("display","none");
	if(display1==""){ window.location.href="../home/page_list.html?parent=7&menu=9";}
	if(display2==""){ window.location.href="../home/page_list.html?parent=7&menu=10";}
	if(display3==""){ window.location.href="../home/page_list.html?parent=7&menu=18";}
	if(display4==""){ window.location.href="../home/page_list.html?parent=7&menu=22";}
}

function tabx(type){
	$.ajax({
		  type: "post",
		  url: "../link/queryLink",
		  data: {
			  'isDel':'1',//前台显示
			  'imgTextType':'1',//文字显示
			  'linkType':linkType//, // 1成员单位  2 省内信用 3省外信用
		  },
		  dataType: "json",
		  success: function(data){
				
		  }
	  })
}

//数据采集
function queryCollection(idstr,page){
	$.ajax({
		  type: "post",
		  url: "../many/queryCollection",
		  data: {
			"page":page
			},
		  dataType: "json",
		  success: function(data){
			var list = data.list;
			var str = '';
			$.each(list, function(index, vo){
				 str+="<tr> <td width='186' class='iconsfris'>"+vo.name+"</td><td width='150'>"+vo.num+"</td><td  width='139'>"+vo.da+"</td></tr>";
			})
			$(idstr).append(str);
		  }
	  })
}
//首页登录框
function MM_showHideLayers() { //v9.0
	  $('#img').val("");
	  $('#img2').val("");
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) 
	  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	    obj.visibility=v; }
}

//首页登录
function login() { 
	var username = $('#img').val();
	var password = $('#img2').val();
	username = username.replace(/\s/g, "");
	password = password.replace(/\s/g, "");
	if(username==""){alert("用户名不能为空！"); return;}
	if(password==""){alert("密码不能为空！"); return;}
	$.ajax({
		  type: "post",
		  url: "../qtuser/queryUser",
		  data: {
			  'username':encode64(username),//用户名
			  'password':encode64(password)//密码
		  },
		  dataType: "json",
		  success: function(data){
				if(data.msg=="登陆成功！"){
					MM_showHideLayers('loginbg','','hide');
					$("#toptl").empty();
					var htmlStr=' <li class="ml15 mr10" ><i class="i i_pc"></i><a id="loginMsg" href="javascript:void(0)"></a></li>'
				       +' <li class="spacer"></li> <li class="mr10"><i class="i i_res"></i><a id="loginMsg1" href="javascript:void(0)">注销2</a></li> '
				       +'<li class="spacer"></li><li><i class="i i_colle"></i><a href="javascript:sc(window.location,document.title)">收藏</a></li>';
					$("#toptl").append(htmlStr);
					$("#loginMsg").text(username);
				    $("#loginMsg").attr("onclick","");
				    $("#loginMsg1").text("注销");
					$("#loginMsg1").attr("onclick","zx();");
				}else{
					MM_showHideLayers('loginbg','','hide')
					$('#img').val("");
					$('#img2').val("");
				}
		  }
	  })
}
//初始化session中的用户
function getSession() {
	$.ajax({
		  type: "post",
		  url: "../qtuser/getSession",
		  dataType: "json",
		  success: function(data){
			  if(data.zt==0){//登录中
				    $("#toptl").empty();
				    var htmlStr=' <li class="ml15 mr10" ><i class="i i_pc"></i><a id="loginMsg" href="javascript:void(0)"  ></a></li>'
				       +' <li class="spacer"></li> <li class="mr10"><i class="i i_res"></i><a id="loginMsg1" href="javascript:void(0)">注销2</a></li> '
				       +'<li class="spacer"></li><li><i class="i i_colle"></i><a href="javascript:sc(window.location,document.title)">收藏</a></li>';
					
					$("#toptl").append(htmlStr);
				    $("#loginMsg").text(data.username);
				    $("#loginMsg").attr("onclick","");
					$("#loginMsg1").text("注销");
					$("#loginMsg1").attr("onclick","zx();");
					$('#username').val(username);
					$('#password').val(password);
					$('#img').val("");
					$('#img2').val("");
			  }else{//未登录
				  $("#toptl").empty();
				  var htmlStr=' <li class="ml15 mr10" ><i class="i i_pc"></i><a id="loginMsg" href="javascript:MM_showHideLayers('+"'loginbg'"+','+"''"+','+"'show'"+');"  >登录</a></li>'
			       +' <li class="spacer"></li> <li class="mr10"><i class="i i_res"></i><a id="loginMsg1" href="page_register.html?parent=90">注册</a></li> '
			       +'<li class="spacer"></li><li><i class="i i_colle"></i><a href="javascript:sc(window.location,document.title)">收藏</a></li>';
				  $("#toptl").append(htmlStr);
			  }
		  }
	  })
}
//注销方法
function zx() {
	$.ajax({
		  type: "post",
		  url: "../qtuser/removeSession",
		  dataType: "json",
		  success: function(data){
	      $("#toptl").empty();
	      var htmlStr=' <li class="ml15 mr10" ><i class="i i_pc"></i><a id="loginMsg" href="javascript:MM_showHideLayers('+"'loginbg'"+','+"''"+','+"'show'"+');"  >登录</a></li>'
	       +' <li class="spacer"></li> <li class="mr10"><i class="i i_res"></i><a id="loginMsg1" href="page_register.html?parent=90">注册</a></li> '
	       +'<li class="spacer"></li><li><i class="i i_colle"></i><a href="javascript:sc(window.location,document.title)">收藏</a></li>';
		  $("#toptl").append(htmlStr);
		 }
	  })
}
//收藏页面
function sc(sURL, sTitle){
	   sURL = encodeURI(sURL); 
       try{   
           window.external.addFavorite(sURL, sTitle);   
       }catch(e) {   
           try{   
               window.sidebar.addPanel(sTitle, sURL, "");   
           }catch (e) {   
               alert("加入收藏失败，请使用Ctrl+D进行添加,或手动在浏览器里进行设置.");
           }   
       }
}

function xysb(menu,type){
	var url="page_service_complain.html?parent=71&menu="+menu+"&fwtype="+type;
	ggxygetSession(url);
}

//时间格式化
Date.prototype.format = function(format){
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(), //day
	"h+" : this.getHours(), //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter
	"S" : this.getMilliseconds() //millisecond
	}

	if(/(y+)/.test(format)) {
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}

	for(var k in o) {
	if(new RegExp("("+ k +")").test(format)) {
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	}
	}
	return format;
	} 



//base64加密开始
var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv"
                + "wxyz0123456789+/" + "=";

function encode64(input) {
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        do {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);
                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;
                if (isNaN(chr2)) {
                        enc3 = enc4 = 64;
                } else if (isNaN(chr3)) {
                        enc4 = 64;
                }
                output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)
                                + keyStr.charAt(enc3) + keyStr.charAt(enc4);
                chr1 = chr2 = chr3 = "";
                enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);

        return output;
}
// base64加密结束